package com.cortex.pineapple.database;

import android.content.Context;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;

public class DbHelper extends SQLiteOpenHelper{

	// name of date base
	public final static String DB_SEASON_QUERY_SEARCH = "dbSeasonQuerySearch";
	// table name of season query search
	public final static String TABLE_SEASON_QUERY_SEARCH = " SeasonQuerySearch ";
	// parameters of season
	public final static String COL_SEASON_ID = " id ";
	public final static String COL_SEASON_NAME = " name ";
	public final static String COL_SEASON_QUERY = " query ";
	public final static String COL_SEASON_VISIT_LINKS_ID = " visitLinks ";
	public final static String COL_SEASON_START_DATE = " startDate ";
	
	// table name of visitLink
	public final static String TABLE_VISIT_LINKS = " VisitLinks ";
	// parameters of visit links
	public final static String COL_VISIT_LINK_ID = " id ";
	public final static String COL_VISIT_LINK_SEASON_ID = " idSeason ";
	public final static String COL_VISIT_LINK_SOURCE = " source ";
	public final static String COL_VISIT_LINK_TITLE = " title ";
	public final static String COL_VISIT_LINK_DESCRIPTION = " description ";
	public final static String COL_VISIT_LINK_URL = " url ";
	public final static String COL_VISIT_LINK_START_DATE = " startDate ";
	public final static String COL_VISIT_LINK_FAVORITE = " isFavorite ";
	public final static String COL_VISIT_LINK_FAVICON = " favicon ";
	public final static String COL_VISIT_LINK_SECTIONS_SELECTED = " sectionsSelected ";

	private final static int version = 1;
	// create season table
	private final static String CREATE_SEASON_TABLE = "create table" 
			+ TABLE_SEASON_QUERY_SEARCH
			+ " (" + COL_SEASON_ID + "integer PRIMARY KEY AUTOINCREMENT," 
			+ COL_SEASON_NAME + "text,"
			+ COL_SEASON_QUERY + "text,"  
			+ COL_SEASON_VISIT_LINKS_ID + "text,"
			+ COL_SEASON_START_DATE + "long)";
	// create visitLinks table
	private final static String CREATE_VISIT_LINKS_TABLE = "create table"
			+ TABLE_VISIT_LINKS
			+ " (" + COL_VISIT_LINK_ID + "integer PRIMARY KEY AUTOINCREMENT," 
			+ COL_VISIT_LINK_SEASON_ID + "integer,"
			+ COL_VISIT_LINK_SOURCE + "integer,"
			+ COL_VISIT_LINK_TITLE + "text,"
			+ COL_VISIT_LINK_DESCRIPTION + "text,"
			+ COL_VISIT_LINK_URL + "text," 
			+ COL_VISIT_LINK_START_DATE + "long,"
			+ COL_VISIT_LINK_FAVORITE + "integer," 
			+ COL_VISIT_LINK_FAVICON + "blob," 
			+ COL_VISIT_LINK_SECTIONS_SELECTED + "text" +")";

	public DbHelper(Context context) {
		super(context, DB_SEASON_QUERY_SEARCH, null, version);
	}

	public void onCreate(SQLiteDatabase db) {
		db.execSQL(CREATE_SEASON_TABLE);
		db.execSQL(CREATE_VISIT_LINKS_TABLE);
	}

	public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
//		if(oldVersion == 1 && newVersion == 2){
//			db.execSQL("ALTER TABLE" + TABLE_VISIT_LINKS +  "ADD COLUMN" + COL_VISIT_LINK_FAVORITE + "integer");
//		}
	}

}
